package com.bt.mapper;

import com.bt.dto.YUserLoginDTO;
import com.bt.entity.YddUser;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Description TODO
 * @Author 青
 * @Date 2023-04-30 0:42
 */
@Mapper
public interface YddUserMapper {
    /**
     * 查询最新注册的6位用户
     *
     * @return
     */
    @Select("SELECT id, username, sex, icon, address\n" +
            "FROM ydd_user\n" +
            "WHERE icon IS NULL OR icon != ''\n" +
            "ORDER BY id DESC\n" +
            "LIMIT 7;")
    List<YddUser> countNewUser();



    /**
     * 查询用户总数
     *
     * @return
     */
@Select("select COUNT(*) from ydd_user")
Integer countUser();

    /**
     * 查询男用户数量
     * @return
     */
    @Select("select COUNT(*) from ydd_user where sex=0;")
    Integer countManNum();
    /**
     * 查询女用户数量
     */
    @Select("select COUNT(*) from ydd_user where sex=1;")
    Integer countWomanNum();

    /**
     * 新增会员接口
     * @param yddUser
     */
    @Insert("insert into ydd_user(username, mobile, sex, password, icon, notes, birthday, address, default_data) " +
            "VALUES(#{username},#{mobile},#{sex},#{password},#{icon},#{notes},#{birthday},#{address},#{defaultData}) ")
    void add(YddUser yddUser);

    /**
     * 会员分页查询接口
     *
     * @param username
     * @param mobile
     * @param sex
     * @return
     */
        Page<YddUser> page(String username, String mobile, String sex);

    /**
     * 修改会员信息接口
     * @param yddUser
     */
    void update(YddUser yddUser);

    /**
     * 删除会员消息
     * @param id
     */
    @Delete("delete from ydd_user where id = #{id}")
    void deleteById(Long id);

    /**
     * 根据id查询会员回显接口
     * @param id
     * @return
     */
    @Select("select * from ydd_user where id = #{id}")
    YddUser findById(Integer id);


    /**
     * 根据手机号查询用户
     * @param mobile
     * @return
     */
    YddUser findByMobile(String mobile);

    void reg(YddUser yddUser);

}
